<template>
  <div class="line-page">
    <headers></headers>
    
    <!-- 搜索区域 -->
    <div class="search-section">
      <div class="search-container">
        <div class="search-form">
          <div class="search-item">
            <i class="el-icon-map-location"></i>
            <el-input
              v-model="search.name"
              placeholder="搜索旅游线路..."
              clearable
              @keyup.enter.native="searchPage"
            ></el-input>
          </div>
          
          <div class="search-item">
            <i class="el-icon-location"></i>
            <el-input
              v-model="search.geography"
              placeholder="地理位置..."
              clearable
            ></el-input>
          </div>
          
          <div class="search-item">
            <i class="el-icon-sunny"></i>
            <el-input
              v-model="search.temperature"
              placeholder="温度范围..."
              clearable
            ></el-input>
          </div>
          
          <el-button 
            type="primary"
            icon="el-icon-search"
            @click="searchPage"
            :loading="loading"
          >
            搜索
          </el-button>
        </div>
      </div>
    </div>

    <!-- 线路列表 -->
    <div class="routes-container">
      <transition-group 
        name="route-list" 
        tag="div" 
        class="routes-grid"
      >
        <div 
          v-for="(item, index) in tableData" 
          :key="item.id"
          class="route-card"
          @click="toInfo(item.id)"
          :style="{ animationDelay: `${index * 0.1}s` }"
        >
          <div class="card-image">
            <img :src="item.images.split(',')[0]" :alt="item.name">
            <div class="image-overlay">
              <span class="view-details">查看详情</span>
            </div>
          </div>
          
          <div class="card-content">
            <h3 class="route-name">{{ item.name }}</h3>
            <p class="route-intro">{{ item.introduce }}</p>
            <div class="route-tags">
              <el-tag size="small" type="success">{{ item.geography }}</el-tag>
              <el-tag size="small" type="warning">{{ item.temperature }}</el-tag>
            </div>
          </div>
        </div>
      </transition-group>

      <!-- 分页器 -->
      <div class="pagination-wrapper">
        <el-pagination
          background
          :page-size="search.pageSize"
          layout="prev, pager, next"
          @current-change="handleCurrentChange"
          :total="total"
          :current-page.sync="search.pageNumber"
        >
        </el-pagination>
      </div>
    </div>

    <bottoms></bottoms>
  </div>
</template>

<script>
import { getSysLinePage } from '../../api/api'
import headers from '@/components/header'
import bottoms from '@/components/bottom'

export default {
  name: 'TourRoutes',
  components: {
    headers,
    bottoms
  },
  data() {
    return {
      search: {
        name: "",
        geography: "",
        temperature: "",
        pageSize: 12,
        pageNumber: 1,
      },
      total: 0,
      tableData: [],
      loading: false
    }
  },
  methods: {
    async searchPage() {
      this.search.pageNumber = 1
      await this.getSysLinePage()
    },
    async getSysLinePage() {
      try {
        this.loading = true
        const res = await getSysLinePage(this.search)
        if (res.code === 1000) {
          this.tableData = res.data.records
          this.total = res.data.total
        }
      } catch (error) {
        this.$message.error('获取数据失败，请稍后重试')
      } finally {
        this.loading = false
      }
    },
    toInfo(id) {
      this.$router.push(`/lineInfo?id=${id}`)
    },
    handleCurrentChange(val) {
      this.search.pageNumber = val
      this.getSysLinePage()
    }
  },
  mounted() {
    this.getSysLinePage()
  }
}
</script>

<style scoped>
.line-page {
  min-height: 100vh;
  background-color: #f5f7fa;
}

.search-section {
  padding: 30px 0;
  background: linear-gradient(135deg, #1e88e5 0%, #1565c0 100%);
}

.search-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.search-form {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
}

.search-item {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-item i {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: #666;
  z-index: 1;
}

.search-item .el-input /deep/ input {
  padding-left: 35px;
  border-radius: 8px;
  height: 40px;
}

.routes-container {
  max-width: 1200px;
  margin: 40px auto;
  padding: 0 20px;
}

.routes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 30px;
  margin-bottom: 40px;
}

.route-card {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.3s ease;
  cursor: pointer;
  animation: fadeInUp 0.5s ease forwards;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.route-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.card-image {
  position: relative;
  height: 200px;
  overflow: hidden;
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.route-card:hover .card-image img {
  transform: scale(1.1);
}

.image-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.3s ease;
}

.route-card:hover .image-overlay {
  opacity: 1;
}

.view-details {
  color: #fff;
  font-size: 16px;
  padding: 8px 20px;
  border: 2px solid #fff;
  border-radius: 20px;
}

.card-content {
  padding: 20px;
}

.route-name {
  margin: 0 0 10px;
  font-size: 18px;
  color: #333;
}

.route-intro {
  color: #666;
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 15px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.route-tags {
  display: flex;
  gap: 10px;
}

.pagination-wrapper {
  text-align: center;
  margin-top: 40px;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .search-form {
    flex-direction: column;
  }
  
  .search-item {
    width: 100%;
  }
  
  .routes-grid {
    grid-template-columns: 1fr;
  }
}
</style>